package com.sukaiyi.giteeideaplugin.cellrenderer;

import cn.hutool.json.JSONObject;
import com.intellij.util.ui.UIUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author sukaiyi
 * @date 2020/07/01
 */
public class RepoListCellRenderer implements ListCellRenderer<JSONObject> {
    @Override
    public Component getListCellRendererComponent(JList<? extends JSONObject> list, JSONObject value, int index, boolean selected, boolean cellHasFocus) {
        RepoListCell repoListCell = new RepoListCell(value);

        Color foreground = repoListCell.isEnabled() ? list.getForeground() : UIUtil.getLabelDisabledForeground();
        Color selectionForeground = list.getSelectionForeground();
        repoListCell.setForeground(selected ? selectionForeground : foreground);

        if (UIUtil.isUnderWin10LookAndFeel()) {
            repoListCell.setBackground(selected ? list.getSelectionBackground() : list.getBackground());
        } else {
            repoListCell.setBackground(selected ? list.getSelectionBackground() : null);
        }
        return repoListCell.getContent();
    }
}
